package com.gitee.wsl.ext.collection


/**
 * Will first put [this]'s elements into chunks of size [chunkSize], then calculate
 * an [average] of each of the chunks.
 *
 */
 fun Sequence<Float>.chunkedAverage(chunkSize: Int): Sequence<Double> = ifEmpty { emptySequence() }
    .chunked(chunkSize.coerceAtLeast(1)) { it.average() }

/**
 * Will first put [this]'s elements into chunks of size [chunkSize], then calculate
 * an [average] of each of the chunks.
 */
 fun Collection<Float>.chunkedAverage(chunkSize: Int): List<Double> = ifEmpty { return emptyList() }
    .chunked(chunkSize.coerceAtLeast(1)) { it.average() }